using System;
using System.Collections.Generic;
using Tools.Domain.Common.Repositories.Contracts;
using Webshop20.Domain.Catalog.Core;
using Webshop20.Domain.Catalog.Services.Contracts;
using Webshop20.Domain.Catalog.Translations.CatalogToOrders;
using Webshop20.Domain.Orders.Core;
using Webshop20.Domain.Orders.Services.Contracts;

namespace Webshop20.Domain.Catalog.Services.Implementation
{
    public class FinishOrderService : IFinishOrderService
    {
        private readonly IOrderTranslator orderTranslator;
        private readonly IRepository<ShoppingCart> orderRepository;
        private readonly IInitializeOrderService initializeOrderService;

        public FinishOrderService(IOrderTranslator orderTranslator, IRepository<ShoppingCart> orderRepository, IInitializeOrderService initializeOrderService)
        {
            this.orderTranslator = orderTranslator;
            this.initializeOrderService = initializeOrderService;
            this.orderRepository = orderRepository;
        }


        public void FinishOrder(int customerId, int cartId, DateTime orderDate)
        {
            var cart = orderRepository.FindById(cartId);
            IList<Position> positions = orderTranslator.convertCartItemsToPositions(cart);
            initializeOrderService.StartOrderProcess(customerId, positions, orderDate);
        }
    }
}